package vo;

import java.io.IOException;
import java.io.Writer;
import java.util.Properties;

/**
 * @author Timur Yarosh
 *         Date: 28.05.13
 *         Time: 10:26
 */
public class Config {
    private Properties props;
    private Writer writer;
    private String path;

    /**
     * @deprecated
     * @param props
     */
    public Config(Properties props) {
        this.props = props;
        this.writer = null;
    }

    public Config(Properties props, Writer writer) {
        this.props = props;
        this.writer = writer;
    }

    public Config(Properties props, String path) {
        this.props = props;
        this.setPath(path);
    }

    public Integer getInteger(String name) {
        String value = this.getValue(name);
        Integer param = null;
        if (value.contains("x")) {
            param = Integer.decode(value);
        } else {
            param = Integer.valueOf(value);
        }
        return param;
    }

    public String getString(String name) {
        return this.getValue(name);
    }

    private String getValue(String name) {
        return props.getProperty(name);
    }

    public void appendProperty(String key, String value) throws IOException {
        props.setProperty(key, value);
//        props.store(writer, null);
    }

    public Properties getProps() {
        return this.props;
    }

    public Writer getWriter() {
        return writer;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }
}
